package com.enqualcomm.kids.mvp.map;

import com.android.volley.VolleyError;
import com.enqualcomm.kids.config.userdefault.AppDefault;
import com.enqualcomm.kids.mvp.NetworkModel;
import com.enqualcomm.kids.network.NetworkListener;
import com.enqualcomm.kids.network.SocketRequest;
import com.enqualcomm.kids.network.socket.request.LocusParams;
import com.enqualcomm.kids.network.socket.response.LocusResult;

/**
 * Created by yinzhiqun on 2015/10/20.
 *
 */
public class LocusModel extends NetworkModel implements ILocusModel {

    private final String userkey;

    public LocusModel(){
        userkey = new AppDefault().getUserkey();
    }


    @Override
    public void locus(String terminalid, String begintime,String endtime,int positiontype,final LocusEventHandler handler) {
        LocusParams locusParams = new LocusParams(userkey,terminalid,begintime,endtime,positiontype);
        loadDataFromServer(new SocketRequest<LocusResult>(locusParams, new NetworkListener<LocusResult>() {
            @Override
            public void onError(VolleyError error) {
                handler.onLocusError();
            }

            @Override
            public void onSuccess(LocusResult response) {
                if (response.code==0){
                    handler.onLocusSuccess(response.result);
                }else{
                    handler.onLocusError();
                }
            }
        }));
    }
}
